package com.icss.ah.auditGoods.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AuditGoodsService {
	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;
	private final Logger errlog = Logger.getLogger("E");
	private final Logger infolog = Logger.getLogger("I");
	
	public List getAuditGoodsList(HashMap map) {
		List list = new ArrayList();
		try{
			list = sqlSessionTemplate.selectList("AuditGoodsBean.getAuditGoodsList", map);
			infolog.info("AuditGoodsService|getAuditGoodsList|list:"+list);
			list = list == null ? new ArrayList() : list;
		} catch (Exception e) {
			e.printStackTrace();
			list = new ArrayList();
			errlog.error("AuditGoodsService|getAuditGoodsList", e);
		}
		return list;
		
	}
	
	public Long getAuditGoodsCount(HashMap map) {
		Long reValue = 0l;
		try {
			reValue = (Long)sqlSessionTemplate.selectOne("AuditGoodsBean.getAuditGoodsCount", map);
			infolog.info("AuditGoodsService|getAuditGoodsCount|reValue:"+reValue);
		} catch (Exception e) {
			e.printStackTrace();
			errlog.error("AuditGoodsService|getAuditGoodsCount", e);
		} 
		return reValue;
	}
	
	public String auditChecked(HashMap map) {
		String result = "1";
		try {
			String refundType =map.get("refundType").toString();
			sqlSessionTemplate.update("AuditGoodsBean.auditChecked", map);	//更新审核状态
			if(refundType.equals("1")){					//审核通过，更新商品状态
				sqlSessionTemplate.update("AuditGoodsBean.refreshGoods", map);	
			}
			infolog.info("AuditGoodsService|auditChecked");
			result = "1";
		} catch (Exception e) {
			e.printStackTrace();
			errlog.error("AuditGoodsService|auditChecked", e);
			result = "0";
		} 
		return result;
	}
	
}
